package com.example.datn.adapter;

import java.util.ArrayList;

import com.example.datn.R;
import com.example.datn.manager.AlbumManager;
import com.example.datn.manager.ResourceManager;
import com.example.datn.objects.AlbumObject;
import com.example.datn.objects.SongObject;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class SongItemAdapter extends ArrayAdapter<SongObject>{

	Activity context = null;
	ArrayList<SongObject> myArray = null;
	int layoutId;
	private static LayoutInflater inflater = null;
	 
	public SongItemAdapter(Activity context, int layoutid, ArrayList<SongObject> arr) {
		super(context, layoutid, arr);
		
		this.context = context;
		this.layoutId = layoutid;
		this.myArray = arr;
		
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {		
		View vi = convertView;
		ViewHolder holder;
		
		if (convertView == null) {
			vi = inflater.inflate(R.layout.my_song_item, null);		
			holder = new ViewHolder();
			holder.tv_item_song_name = (TextView)vi.findViewById(R.id.tv_song_item_name);
			holder.tv_item_song_album = (TextView)vi.findViewById(R.id.tv_song_item_album);
			
			vi.setTag(holder);
		}
		else{
			holder = (ViewHolder) vi.getTag();
		}
		
		SongObject song = myArray.get(position);
		
		holder.tv_item_song_name.setText(song.songName);
		
		holder.tv_item_song_album.setText(song.albumName);
		
		return vi;		
	}

	private static class ViewHolder {
	    public TextView tv_item_song_name;
	    public TextView tv_item_song_album;
	}
	
}
